//配置设置失效、锁定的通用类路径
var statuPrefix = ctx + "welfare";
//失效状态是1，未失效是0
//锁定状态是1，未锁定是0

//失效(Disabled)
function DisabledState(row, table) {
    if (row.isdisabled == 0) {
        return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="DisabledClose(\'' + row.id + '\',\'' + table + '\')"></i> ';
    } else {
        return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="DisabledOpen(\'' + row.id + '\',\'' + table + '\')"></i> ';
    }
}

function DisabledClose(id, table) {
    $.modal.confirm("确认设置失效吗？", function () {
        $.operate.post(statuPrefix + "/changeDisabled", {"id": id, "isDisabled": 1, "table": table});
    })
}

function DisabledOpen(id, table) {
    $.modal.confirm("确认设置启用吗？", function () {
        $.operate.post(statuPrefix + "/changeDisabled", {"id": id, "isDisabled": 0, "table": table});
    })
}


//锁定(islock)
function islockState(row, table) {
    if (row.islock == 0) {
        return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="islockOpen(\'' + row.id + '\',\'' + table + '\')"></i> ';
    } else {
        return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="islockClose(\'' + row.id + '\',\'' + table + '\')"></i> ';
    }
}

//取消锁定
function islockClose(id, table) {
    $.modal.confirm("确认取消锁定吗？", function () {
        $.operate.post(statuPrefix + "/changeIslock", {"id": id, "islock": 0, "table": table});
    })
}

//设置锁定
function islockOpen(id, table) {
    $.modal.confirm("确认设置锁定吗？", function () {
        $.operate.post(statuPrefix + "/changeIslock", {"id": id, "islock": 1, "table": table});
    })
}

//修改时判断是否锁定
function editIslock(id, islock) {
    if (id == undefined && islock == undefined) {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row[0].islock == 1) {
            $.modal.alertWarning("该项已锁定!");
            return;
        }
    } else {
        if (islock == 1) {
            $.modal.alertWarning("该项已锁定!");
            return;
        }
    }
    $.operate.edit(id);
}

//批量删除时判断是否有锁定项
function removeAllIslock() {
    var row = $("#bootstrap-table").bootstrapTable('getSelections');
    for (var i = 0; i < row.length; i++) {
        if (row[i].islock == 1) {
            $.modal.alertWarning("存在锁定项!");
            return;
        }
    }
    $.operate.removeAll();
}

//单个删除时判断是否锁定
function removeIslock(id, islock) {
    if (id == undefined && islock == undefined) {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row[0].islock == 1) {
            $.modal.alertWarning("该项已锁定!");
            return;
        }
    } else {
        if (islock == 1) {
            $.modal.alertWarning("该项已锁定!");
            return;
        }
    }
    $.operate.remove(id);
}

function edit(id, islock){
    if(islock == undefined){
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        for (var i = 0; i < row.length; i++) {
            if (row[i].islock == 1) {
                $.modal.alertWarning("存在锁定项!");
                return;
            }
        }
        $.operate.edit(id);
    }else{
        if(islock == 1){
            $.modal.alertWarning("存在锁定项!");
            return;
        }
        $.operate.edit(id);
    }


}


